<template>
  <div class="draw-body">
    <div class="wise-form">
       
      <el-form   
          :model='object'
           ref="ruleForm" 
           :validate-on-rule-change="false"
           :rules='rules'
            label-width="130px"
             label-suffix=":" >
        <el-form-item label="作业单位" prop="name">
         
          <el-input
            placeholder="请输入作业单位"
            :maxlength="100"
            v-model='object.name'
           
            show-word-limit
            clearable
            autofocus
          />
        </el-form-item>
        <el-form-item label="项目地址" prop="area">
          <wise-region v-model="object.area" :obj-keys="[
                {
                  field: 'province',
                  key: 'province',
                  value: 'key',
                },
                {
                  field: 'provinceName',
                  key: 'province',
                  value: 'value',
                  tableShow: true,
                },
                {
                  field: 'city',
                  key: 'city',
                  value: 'key',
                },
                {
                  field: 'cityName',
                  key: 'city',
                  value: 'value',
                  tableShow: true,
                },
                {
                  field: 'country',
                  key: 'area',
                  value: 'key',
                },
                {
                  field: 'countryName',
                  key: 'area',
                  value: 'value',
                  tableShow: true,
                },
                {
                  field: 'street',
                  key: 'town',
                  value: 'key',
                },
                {
                  field: 'streetName',
                  key: 'town',
                  value: 'value',
                  tableShow: true,
                },
              ]" @on-value="setValue" />
        </el-form-item>
        <el-form-item label="详细地址" prop="area">
          <el-input
            placeholder="请输入详细地址"
            v-model="object.address"
            :maxlength="100"
            show-word-limit
            clearable
            autofocus
          />
        </el-form-item>
        <el-form-item label="项目开始时间" prop="bgTime">
          <wise-date  v-model='object.bgTime' type="datetime" format="yyyy-MM-dd HH:mm:ss" />
        </el-form-item>
        <el-form-item label="项目结束时间" prop="edTime">
          <wise-date  v-model='object.edTime' type="datetime" format="yyyy-MM-dd HH:mm:ss" />
        </el-form-item>

        <el-form-item label="动火级别" prop="dhjb"> 
          <el-select v-model='object.dhjb'>
              <el-option
                v-for='item in dhListData'
                :key='item.id'
                :label='item.name'
                :value='item.name'
              />
            </el-select>
        </el-form-item>
        <el-form-item label="计划管理类型" prop="xffsid"> 
          <el-select v-model='object.xffsid'>
              <el-option
                v-for='item in  jhListData'
                :key='item.id'
                :label='item.namex'
                :value='item.id'
              />
            </el-select>
        </el-form-item>
        <el-form-item label="视频选择" prop="videoids">
          <el-select
              v-model='object.videoids'
              class='detection'
              placeholder='请输入'
              multiple
            >
              <el-option
                v-for='(item, index) in spListData'
                :key='index'
                :label='item.name'
                :value='item.id'
              />
            </el-select>
        </el-form-item>
         
        <el-form-item label="质量终端选择" prop="zlids">
          <el-select
              v-model='object.zlids'
              class='detection'
              placeholder='请选择终端'
              multiple
            >
              <el-option
                v-for='(item, index) in zlListData'
                :key='index'
                :label='item.hjEquipmentInfo.name'
                :value='item.hjEquipmentInfo.id'
              />
            </el-select>
        </el-form-item>
        <el-form-item label="环境终端选择" prop="aqids">
          <el-select
              v-model='object.aqids'
              class='detection'
              placeholder='请选择终端'
           
            >
              <el-option
                v-for='(item, index) in aqListData'
                :key='index'
                :label='item.hjEquipmentInfo.name'
                :value='item.hjEquipmentInfo.id'
              />
            </el-select>
        </el-form-item>
        <el-form-item label="切断终端选择" prop="latitude">
          <el-select
              v-model='object.qdids'
              class='detection'
              placeholder='请选择终端'
              multiple
            >
              <el-option
                v-for='(item, index) in qdListData'
                :key='index'
                :label='item.hjEquipmentInfo.name'
                :value='item.hjEquipmentInfo.id'
              />
            </el-select>
        </el-form-item>
        <el-form-item label="人员选择"  prop="hgsl">
          焊工数：<el-input-number
          v-model='object.hgsl'
            placeholder=""
            :maxlength="10"
            :min="0"
            :cobtrols="false"
            show-word-limitclearable
            autofocus
            style="width: 120px"
          />
          管 工 数 ：<el-input-number
          v-model='object.ggsl'
            placeholder=""
            :maxlength="10"
            :min="0"
            :cobtrols="false"
            show-word-limitclearable
            autofocus
            style="width: 120px"
          />
          安全员数：<el-input-number
          v-model='object.aqysl'
            placeholder=""
            :maxlength="10"
            :min="0"
            :cobtrols="false"
            show-word-limitclearable
            autofocus
            style="width: 120px"
          />
          <br />
          电工数：<el-input-number
          v-model='object.dgsl'
            placeholder=""
            :maxlength="10"
            :min="0"
            :cobtrols="false"
            show-word-limitclearable
            autofocus
            style="width: 120px"
          />
          其他工人数：<el-input-number
          v-model='object.qtsl'
            placeholder=""
            :maxlength="10"
            :min="0"
            :cobtrols="false"
            show-word-limitclearable
            autofocus
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="大屏名称" prop="screenName">
          <el-input
              v-model='object.screenName'
              :rules='rules'
              placeholder='请输入大屏名称'
              :maxlength='100'
              show-word-limitclearable
              autofocus
            />
        </el-form-item>
        <el-form-item label="大屏LOGO" prop="logo">
          <wise-file
              v-model='object.logo'
              upload-type='image'
              :limit='1'
              :max-file-size='100 * 1024 * 1024'
            />  
        </el-form-item>

        <el-form-item label="动火 方案" prop="construction">
          <wise-file
              v-model='object.construction'
              upload-type='file'
              :limit='1'
              :max-file-size='100 * 1024 * 1024'
            />
        </el-form-item>
        <el-form-item label="同步到云端" prop="tbyd"> 
          <el-switch v-model="object.tbyd" :active-value="1"
            :inactive-value="0" >
                    
                  </el-switch>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"  >提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import WiseFile from '@/components/Crud/components/wiseFile';
import WiseRegion from '@/components/Crud/components/wiseRegion';
import WiseDate from '@/components/Crud/components/wiseDate';
import { postHandle } from '@/api';
export default {
  components: {
    WiseRegion,
    WiseDate,
    WiseFile,
  },
  data() {
    return {
      
      urls: {
        list: '/api/v1/welder-sbtx-second/project-info-comb/list',
        add: '/api/v1/welder-sbtx-second/project-info-comb/createKs',
        show: '/api/v1/welder-sbtx-second/project-info-comb/show/',
        update: '/api/v1/welder-sbtx-second/project-info-comb/updateKs',
      },
      object: {
        name: null,
        screenName: null,
        logo: null,
        serialNum: null,
        province: null,
        city: null,
        county: null,
        street: null,
        provinceName: null,
        cityName: null,
        countryName: null,
        streetName: null,
        address: null,
        companyName: null,
        manager: null,
        typeCode: null,
        phone: null,
        zlids:[],
        aqids:null,
        qdids:[],
        file: [],
        remark: null,
        
        welderNumber: null,
        userId: null,
        startTime: "",
        endTime: "",
        hotLevel: null,
        hotEntName: null,
        repairMethod: null,
        weldAllNumber: null,
        weldFinshNumber: null,
        portraitWeldAllNumber: null,
        portraitWeldFinshNumber: null,
        cinctureWeldAllNumber: null,
        cinctureWeldFinshNumber: null,
        construction: null,
       
        hgsl: null,
        ggsl: null,
        
        dgsl: null,
        aqysl: null,
        qtsl: null,
      },
      rules: {
        name: [
          {
            required: true,
            message: '请输入作业单位',
            trigger: 'blur',
          },
        ],
        welderNumber: [
          {
            required: true,
            message: '请输入项目编号',
            trigger: 'blur',
          },
        ],
        xffsid: [
          {
            required: true,
            message: '请选择项目计划',
            trigger: 'blur',
          },
        ],
        area: [
          {
            required: false,
            message: '请选择地址',
            trigger: 'blur',
          },
        ],  videoids: [
          {
            required: true,
            message: '请选择视频',
            trigger: 'blur',
          },
        ], zlids: [
          {
            required: true,
            message: '请选择质量终端',
            trigger: 'blur',
          },
        ], aqids: [
          {
            required: true,
            message: '请选择环境终端',
            trigger: 'blur',
          },
        ], hgsl: [
          {
            required: true,
            message: '请选择人员',
            trigger: 'blur',
          },
        ], construction: [
          {
            required: true,
            message: '请上传动火方案',
            trigger: 'blur',
          },{
              pattern: /^.+(\.pdf)$/,
              message: '动火方案应为pdf格式'
            }
        ], dhjb: [
          {
            required: true,
            message: '请选择动火级别',
            trigger: 'blur',
          },
        ],
        address: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur',
          },
          
         // 5、计划管理、视频选择、质量终端、环境终端、人员选择、动火方案
        ],
        // : 0,
        
        bgTime: [
          {
            required: true,
            message: '请选择项目开始时间',
            trigger: 'blur',
          },
        ],
        edTime: [
          {
            required: true,
            message: '请选择项目结束时间',
            trigger: 'blur',
          },
        ],
        hotLevel: [
          {
            required: true,
            message: '请输入动火等级',
            trigger: 'blur',
          },
        ],
        hotEntName: [
          {
            required: true,
            message: '请输入动火作业单位',
            trigger: 'blur',
          },
        ],
        repairMethod: [
          {
            required: true,
            message: '请输入生产计划',
            trigger: 'blur',
          },
        ],

        screenName: [
          {
            required: true,
            message: '请输入大屏名称',
            trigger: 'blur',
          },
        ],
      },
      //质量终端选项
      zlListData: [],
      //安全终端选项
      aqListData: [],
      //切断终端选项
      qdListData: [],
      //视频选项
      spListData: [],
      //动火选项
      dhListData: [],
      //计划选项
      jhListData: []
    }
  }, computed: {
    entSpaceId() {
      //return this.$store.getters.entSpaceId;
    },
  },
  created() {
    // this.getCraftsInfoList();
     this.getCraftsInfoList();
  },
  methods: {
    setValue(objVal) {
      if (objVal && objVal.length > 0) {
        objVal.forEach((item) => {
          this.$set(this.object, item.field, item.value);
        });
      }
    },
    getCraftsInfoList(){
      const reqjh = {  d: { filters: [  
           { field: 'spaceId',  operator: 'EQUALS', value: this.$store.getters.entSpaceId, },
          // { field: 'sp', operator: 'EQUALS',  value: 1, },
         ],
          page: {  p: 1,  ps: 9999, }, },
      };
      postHandle('/api/v1/welder-sbtx-second/repair-mode-comb/list', reqjh).then(
         (response) => {
          const data = response.result;
          this.jhListData = data;
        }
      );

      const reqdh = {  d: { filters: [ 
          {  field: 'pdCode', operator: 'EQUALS', value: 'DHJB', },
          {  field: 'st', operator: 'NE', value: 9, }, ],
          page: {  p: 1, ps: 9999, },
          retOnlySt: false,
          sorts: [ { field: 'ct', isDesc: true, }, ],
        },
      };
      postHandle('/api/v1/welder-sbtx-second/dictionary', reqdh).then(
        (res) => {
          this.dhListData = res.result;
        }
      );

      const reqsp = { d: { filters: [
            { field: 'pdCode', operator: 'EQUALS', value: 'DHJB', },
            {  field: 'st',  operator: 'NE', value: 9,  }, ],
          page: {  p: 1,  ps: 9999, },
          retOnlySt: false,
          sorts: [ { field: 'ct', isDesc: true, }, ],
        },
      };
      postHandle('/api/v1/welder-sbtx-second/video-comb/listqy', reqsp).then(
        (res) => {
          this.spListData = res.result;
        }
      );


      const reqzl = {  d: { filters: [  
          { field: 'entSpaceId',  operator: 'EQUALS', value:  this.$store.getters.entSpaceId, },
          { field: 'gatewayType',  operator: 'EQUALS', value: "welder", },
          { field: 'sp', operator: 'EQUALS',  value: 1, }, ],
          page: {  p: 1,  ps: 9999, }, },
      };
      postHandle('/api/v1/welder-sbtx-second/gateway-equipment-comb/list', reqzl).then(
        (response) => {
          const data = response.result;
          this.zlListData = data;
        }
      );

      const reqaq = {  d: { filters: [ 
        { field: 'entSpaceId',  operator: 'EQUALS', value:  this.$store.getters.entSpaceId, },
        { field: 'gatewayType',  operator: 'EQUALS', value:"safety", },
        {  field: 'st', operator: 'NE', value: 9, }, ],
          page: {  p: 1, ps: 9999, },
          retOnlySt: false,
          sorts: [ { field: 'ct', isDesc: true, }, ],
        },
      };
      postHandle('/api/v1/welder-sbtx-second/gateway-equipment-comb/list', reqaq).then(
        (res) => {
          this.aqListData = res.result;
        }
      );

      const reqqd = { d: { filters: [
            { field: 'entSpaceId',  operator: 'EQUALS', value:  this.$store.getters.entSpaceId, },
            { field: 'gatewayType',  operator: 'EQUALS', value: "shear", },
            {  field: 'st',  operator: 'NE', value: 9,  }, ],
          page: {  p: 1,  ps: 9999, },
          retOnlySt: false,
          sorts: [ { field: 'ct', isDesc: true, }, ],
        },
      };
      postHandle('/api/v1/welder-sbtx-second/gateway-equipment-comb/list', reqqd).then(
        (res) => {
          this.qdListData = res.result;
        }
      );



      

      // const params2 = {
      //   d: {
      //     filters: [
      //       {
      //         field: 'pdCode',
      //         operator: 'EQUALS',
      //         value: 'DHJB',
      //       },
      //       {
      //         field: 'st',
      //         operator: 'NE',
      //         value: 9,
      //       },
      //     ],
      //     page: {
      //       p: 1,
      //       ps: 9999,
      //     },
      //     retOnlySt: false,
      //     sorts: [
      //       {
      //         field: 'ct',
      //         isDesc: true,
      //       },
      //     ],
      //   },
      // };
      // const params3 = {
      //   d: {
      //     filters: [
      //       {
      //         field: 'pdCode',
      //         operator: 'EQUALS',
      //         value: 'DHJB',
      //       },
      //       {
      //         field: 'st',
      //         operator: 'NE',
      //         value: 9,
      //       },
      //     ],
      //     page: {
      //       p: 1,
      //       ps: 9999,
      //     },
      //     retOnlySt: false,
      //     sorts: [
      //       {
      //         field: 'ct',
      //         isDesc: true,
      //       },
      //     ],
      //   },
      // };
      // const params4 = {
      //   d: {
      //     filters: [
      //       {
      //         field: 'pdCode',
      //         operator: 'EQUALS',
      //         value: 'DHJB',
      //       },
      //       {
      //         field: 'st',
      //         operator: 'NE',
      //         value: 9,
      //       },
      //       {
      //         field: 'entSpaceId',
      //         operator: 'EQUALS',
      //         value: this.entSpaceId,
      //       },
      //     ],
      //     page: {
      //       p: 1,
      //       ps: 9999,
      //     },
      //     retOnlySt: false,
      //     sorts: [
      //       {
      //         field: 'ct',
      //         isDesc: true,
      //       },
      //     ],
      //   },
      // };
      
      // postHandle('/api/v1/welder-sbtx-second/dictionary', params1).then(
      //   (res) => {
      //     this.dhlvListData = res.result;
      //   }
      // );
      // postHandle(
      //   '/api/v1/welder-sbtx-second/repair-mode-comb/list',
      //   params2
      // ).then((res) => {
      //   this.xffsListData = res.result;
      // });
      // postHandle(
      //   '/api/v1/welder-sbtx-second/video-comb/listqy',
      //   params3
      // ).then((res) => {
      //   this.sxtListData = res.result;
      // });
      // postHandle(
      //   '/api/v1/welder-sbtx-second/hj-equipment-info-comb/list',
      //   params4
      // ).then((res) => {
      //   this.zdListData = res.result;
      // });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url;
          if (this.object.id) {
            url = this.urls.update ;
          } else {
            url = this.urls.add;
          }
          postHandle(url, {
            obj: {
              ...this.object,
              initiateProjectId: this.initiateProjectId,
            },
          })
            .then((response) => {
              this.$message('操作成功');
              this.drawer = false;
              console.log(this.object.id)
              if (this.object.id) {
                this.$emit('refreshTable');
              } else {
                this.$router.push({
                  name: 'CreateProject',
                });
              }
            })
            .catch((error) => {
              const data = error.response.data;
              for (const key in data) {
                this.$message.error(this.$t(key + '.' + data[key]));
              }
            });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.draw-body {
  padding-top: 50px;
  padding-left: 250px;
  padding-right: 250px;
   
}
.wise-form{
  width: 700px;
}
.el-form-item {
  margin-bottom: 15px;
}
</style>
